package com.hg.hggood.controller;


import com.hg.hggood.service.ISMSService;
import com.hg.hggood.util.JsonResult;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@CrossOrigin(value = "http://localhost:8081")
@RequestMapping("sms")
@RestController//@Controller+@ResponseBodyX
public class SMSController extends  BaseController{
    @Autowired
    private ISMSService smsService;

    @RequestMapping("{phone}/{templateID}/send")
    public JsonResult<Void> sendSMS(
            @PathVariable String phone,
            @PathVariable String templateID,
            HttpSession session) throws TencentCloudSDKException {
        smsService.sendSMS(
                getuidFromSession(session),
                getUsernameFromSession(session),
                phone,
                templateID);
        return new JsonResult<>(OK);
    }

    @RequestMapping("{checkNum}/check")
    public JsonResult<Void> checkSMS(
            @PathVariable String checkNum,
            HttpSession session){
        smsService.checkSMS(
                getuidFromSession(session),
                getUsernameFromSession(session),
                checkNum);
        return new JsonResult<>(OK);
    }
}
